home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / smalltlk.zip / PRELUDE / SEMAPHOR.ST < prev    next >
Text File  |  1987-06-17  |  640b  |  25 lines

  1. Class  Semaphore :List
  2. | excessSignals |
  3.  
  4. [  new
  5.     excessSignals <- 0
  6.  
  7. |  new: aNumber
  8.     excessSignals <- aNumber
  9.  
  10. |  signal
  11.     <StartAtomic>.    "start atomic action"
  12.     (self isEmpty)
  13.       ifTrue: [excessSignals <- excessSignals + 1]
  14.       ifFalse: [self removeFirst unblock].
  15.     <EndAtomic>        "end atomic action"
  16.  
  17. |  wait
  18.     <StartAtomic>.    "start atomic actions"
  19.     (excessSignals = 0)
  20.       ifTrue: [self addLast: selfProcess.
  21.            selfProcess block]
  22.       ifFalse: [excessSignals <- excessSignals - 1].
  23.     <EndAtomic>        "end atomic actions"
  24. ]
  25.